package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.happy.cat.common.utils.poi.ExcelUtil;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.framework.web.page.TableDataInfo;
import com.happy.cat.project.system.domain.UserImAuthority;
import com.happy.cat.project.system.service.IUserImAuthorityService;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 用户交互权限Controller
 *
 * @author verne
 * @date 2020-08-04
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/userImAuthority" )
@Api("用户交互权限 API")
public class UserImAuthorityController extends BaseController {

    private final IUserImAuthorityService iUserImAuthorityService;

    /**
     * 查询用户交互权限列表
     */
    @ApiOperation(value = "查询用户交互权限列表",notes = "查询用户交互权限列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:userImAuthority:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserImAuthority userImAuthority)
    {
        startPage();
        LambdaQueryWrapper<UserImAuthority> lqw = new LambdaQueryWrapper<UserImAuthority>();
        if (userImAuthority.getUserId() != null){
            lqw.eq(UserImAuthority::getUserId ,userImAuthority.getUserId());
        }
        if (userImAuthority.getChatEnable() != null){
            lqw.eq(UserImAuthority::getChatEnable ,userImAuthority.getChatEnable());
        }
        if (userImAuthority.getEnvelopeEnable() != null){
            lqw.eq(UserImAuthority::getEnvelopeEnable ,userImAuthority.getEnvelopeEnable());
        }
        if (userImAuthority.getChatroomEnable() != null){
            lqw.eq(UserImAuthority::getChatroomEnable ,userImAuthority.getChatroomEnable());
        }
        if (userImAuthority.getFollowingEnable() != null){
            lqw.eq(UserImAuthority::getFollowingEnable ,userImAuthority.getFollowingEnable());
        }
        if (userImAuthority.getGiveEnable() != null){
            lqw.eq(UserImAuthority::getGiveEnable ,userImAuthority.getGiveEnable());
        }
        if (userImAuthority.getSubscribeEnable() != null){
            lqw.eq(UserImAuthority::getSubscribeEnable ,userImAuthority.getSubscribeEnable());
        }
        if (userImAuthority.getTimeLimit() != null){
            lqw.eq(UserImAuthority::getTimeLimit ,userImAuthority.getTimeLimit());
        }
        List<UserImAuthority> list = iUserImAuthorityService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出用户交互权限列表
     */
    @ApiOperation(value = "导出用户交互权限列表",notes = "导出用户交互权限列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userImAuthority:export')" )
    @Log(title = "用户交互权限" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(UserImAuthority userImAuthority) {
        LambdaQueryWrapper<UserImAuthority> lqw = new LambdaQueryWrapper<UserImAuthority>(userImAuthority);
        List<UserImAuthority> list = iUserImAuthorityService.list(lqw);
        ExcelUtil<UserImAuthority> util = new ExcelUtil<UserImAuthority>(UserImAuthority. class);
        return util.exportExcel(list, "userImAuthority" );
    }

    /**
     * 获取用户交互权限详细信息
     */
    @ApiOperation(value = "获取用户交互权限详细信息",notes = "获取用户交互权限详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userImAuthority:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iUserImAuthorityService.getById(id));
    }

    /**
     * 新增用户交互权限
     */
    @ApiOperation(value = "新增用户交互权限",notes = "新增用户交互权限",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userImAuthority:add')" )
    @Log(title = "用户交互权限" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserImAuthority userImAuthority) {
        return toAjax(iUserImAuthorityService.save(userImAuthority) ? 1 : 0);
    }

    /**
     * 修改用户交互权限
     */
    @ApiOperation(value = "修改用户交互权限",notes = "修改用户交互权限",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userImAuthority:edit')" )
    @Log(title = "用户交互权限" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserImAuthority userImAuthority) {
        return toAjax(iUserImAuthorityService.updateById(userImAuthority) ? 1 : 0);
    }

    /**
     * 删除用户交互权限
     */
    @ApiOperation(value = "删除用户交互权限",notes = "删除用户交互权限",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userImAuthority:remove')" )
    @Log(title = "用户交互权限" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iUserImAuthorityService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
